

package blogs.eidos.cloud.framework.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.bigdata.cloud.framework.common.api.HttpCodeEnum;
import net.bigdata.cloud.framework.common.api.Resp;
import net.bigdata.cloud.framework.common.dto.BasePageDto;
import net.bigdata.cloud.framework.common.service.impl.BaseServiceImpl;
import net.bigdata.cloud.framework.log.entity.SysOperationLog;
import net.bigdata.cloud.framework.log.mapper.SysOperationLogMapper;
import net.bigdata.cloud.framework.log.service.SysOperationLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 系统操作日志 服务实现类
 *
 * @author Eidos
 * @since 2020-03-19
 */
@Slf4j
@Service
public class SysOperationLogServiceImpl extends BaseServiceImpl<SysOperationLogMapper, SysOperationLog> implements SysOperationLogService {

    @Autowired
    private SysOperationLogMapper sysOperationLogMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Resp<IPage<SysOperationLog>> getPage(BasePageDto dto) {
        try {
            Page<SysOperationLog> page = new Page<>(dto.getCurrent(), dto.getPageSize());
            QueryWrapper<SysOperationLog> wrapper = new QueryWrapper<>();
            IPage<SysOperationLog> iPage = sysOperationLogMapper.selectPage(page, wrapper);
            return Resp.success(iPage);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_FAILURE_ERROR);
        }
    }

}
